package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.MallProductDescriptionLanguage;
import com.novax.ex.activity.infrastructure.mapper.MallProductDescriptionLanguageMapper;
import com.novax.ex.activity.open.model.response.MallPrizeResponse;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.enums.LanguageType;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.Objects;

/**
 * Description:简介配置
 *
 * @author Deucalion@novax.email
 * @date 2023/2/21 17:21
 */
@Service
public class MallProductDescriptionLanguageService extends BaseService {
    @Resource
    private MallProductDescriptionLanguageMapper mallProductDescriptionLanguageMapper;
    @Override
    protected BaseMapper getBaseMapper() {
        return mallProductDescriptionLanguageMapper;
    }

    /** 根据语言查询数据 */
    public MallProductDescriptionLanguage findByLanguage(Long mallProductId, String language) {
        return mallProductDescriptionLanguageMapper.selectByLanguage(mallProductId,language);
    }

    /**
     * @description: 获取商品简介
     * @author: Wade
     * @date: 2/22/23 4:46 PM
     * @param: [prize, language]
     * @return: void
     **/
    public String getDescriptionByLanguage(Long mallProductId, String language) {
        MallProductDescriptionLanguage descriptionLanguage = mallProductDescriptionLanguageMapper.selectByLanguage(mallProductId, language);
        if (Objects.isNull(descriptionLanguage)) {
            //在查一次英语
            descriptionLanguage = mallProductDescriptionLanguageMapper.selectByLanguage(mallProductId, LanguageType.en.getType());
            if (Objects.nonNull(descriptionLanguage)) {
                return descriptionLanguage.getContent();
            }
        } else {
            return descriptionLanguage.getContent();
        }
        return "";
    }
}
